<template>
	<view>
		
		<!-- #ifdef APP-VUE -->
		<view style="width: 100%;height: 50px;"></view>
		<!-- #endif -->
		<view class="h100 bg-white">
			<view class="cu-bar">
				<view class="action" @tap="BackPage(2)">
					<text class="cuIcon-back"></text>
				</view>
				<view class="content">
					支付中心
				</view>
			</view>
			<view class="margin-top-xl text-center padding-top">
				<view class="text-gray">{{title}}</view>
				<view class="text-price text-black text-xxl margin-top">{{detail?detail.pay_money:0.00}}</view>
			</view>
			<view class="margin-top-xl margin-lr-xl padding-top-xl text-center" v-if="detail">
				<view>
					<text v-if="detail.order_status == 20" class="text-red">审核中</text>
					<text v-else-if="detail.order_status < 0" class="text-gray">订单已关闭</text>
					<text v-else-if="detail.order_status > 0" class="text-green">订单已支付</text>
				</view>
			</view>
			<block v-if="detail && (detail.order_status == 0 || detail.order_status == 21)">
				<view class="margin-top-xl margin-lr-xl padding-top-xl" v-if="detail.is_channel == 0">
					<view class="margin-lr-xl">
						<!-- #ifdef H5 -->
						<view class="space-between solid-bottom padding-tb-sm align-center" @tap="PaymentBingChange('wechat')" v-if="detail.payment_list.order_wechat_pay == 1">
							<view class="cu-avatar bg-white">
								<image src="@/static/cash_wx.png" mode="aspectFit"></image>
							</view>
							<view class="w100 margin-left">
								<view class="text-black text-lg">微信支付</view>
								<view class="text-gray text-sm">推荐使用微信支付</view>
							</view>
							<view class="">
								<radio :class="payment=='wechat'?'checked':''" :checked="payment=='wechat'?true:false" value="wechat"></radio>
							</view>
						</view>
						
						<view class="space-between solid-bottom padding-tb-sm align-center" @tap="PaymentBingChange('hj')" v-if="detail.payment_list.order_hj_wechat_pay == 1">
							<view class="cu-avatar bg-white">
								<image src="@/static/cash_wx.png" mode="aspectFit"></image>
							</view>
							<view class="w100 margin-left">
								<view class="text-black text-lg">微信支付</view>
								<view class="text-gray text-sm">推荐使用微信支付</view>
							</view>
							<view class="">
								<radio :class="payment=='hj'?'checked':''" :checked="payment=='hj'?true:false" value="hj"></radio>
							</view>
						</view>
						
						<view class="space-between solid-bottom padding-tb-sm align-center" @tap="PaymentBingChange('gd')" v-if="detail && detail.payment_list.order_gd_wechat_pay == 1">
							<view class="cu-avatar bg-white">
								<image src="@/static/cash_wx.png" mode="aspectFit"></image>
							</view>
							<view class="w100 margin-left">
								<view class="text-black text-lg">微信支付</view>
								<view class="text-gray text-sm">推荐使用微信支付</view>
							</view>
							<view class="">
								<radio :class="payment=='gd'?'checked':''" :checked="payment=='gd'?true:false" value="gd"></radio>
							</view>
						</view>
						<!-- #endif -->
						
						<!-- #ifdef APP-VUE -->
						<view class="space-between solid-bottom padding-tb-sm align-center" @tap="PaymentBingChange('hjapp')" v-if="detail.payment_list.order_hj_wechat_pay == 1">
							<view class="cu-avatar bg-white">
								<image src="@/static/cash_wx.png" mode="aspectFit"></image>
							</view>
							<view class="w100 margin-left">
								<view class="text-black text-lg">微信支付</view>
								<view class="text-gray text-sm">推荐使用微信小程序支付</view>
							</view>
							<view class="">
								<radio :class="payment=='hjapp'?'checked':''" :checked="payment=='hjapp'?true:false" value="hjapp"></radio>
							</view>
						</view>
						<!-- #endif -->
						
						<view class="space-between solid-bottom padding-tb-sm align-center" @tap="PaymentBingChange('Alipay')" v-if="detail.payment_list.order_ali_pay == 1">
							<view class="cu-avatar bg-white">
								<image src="@/static/cash_ali.png" mode="aspectFit"></image>
							</view>
							<view class="w100 margin-left">
								<view class="text-black text-lg">支付宝支付</view>
								<view class="text-gray text-sm">需要跳转网页支付</view>
							</view>
							<view class="">
								<radio :class="payment=='Alipay'?'checked':''" :checked="payment=='Alipay'?true:false" value="Alipay"></radio>
							</view>
						</view>
						<view class="space-between  padding-tb-sm align-center" @tap="PaymentBingChange('gd1')" v-if="detail && detail.payment_list.order_gd_ali_pay == 1">
							<view class="cu-avatar bg-white">
								<image src="@/static/cash_ali.png" mode="aspectFit"></image>
							</view>
							<view class="w100 margin-left">
								<view class="text-black text-lg">支付宝支付</view>
								<view class="text-gray text-sm">推荐使用支付宝支付</view>
							</view>
							<view class="">
								<radio :class="payment=='gd1'?'checked':''" :checked="payment=='gd1'?true:false" value="gd1"></radio>
							</view>
						</view>
						
						<view class="space-between  padding-tb-sm align-center" @tap="PaymentBingChange('hj1')" v-if="detail && detail.payment_list.order_hj_alipay_pay == 1">
							<view class="cu-avatar bg-white">
								<image src="@/static/cash_ali.png" mode="aspectFit"></image>
							</view>
							<view class="w100 margin-left">
								<view class="text-black text-lg">支付宝支付</view>
								<view class="text-gray text-sm">推荐使用支付宝汇聚支付</view>
							</view>
							<view class="">
								<radio :class="payment=='hj1'?'checked':''" :checked="payment=='hj1'?true:false" value="hj1"></radio>
							</view>
						</view>
						
						<view class="space-between  padding-tb-sm align-center" @tap="PaymentBingChange('kf')" v-if="detail && detail.payment_list.order_hj_kf_pay == 1">
							<view class="cu-avatar bg-white">
								<image src="../../../static/ylkf.png" mode="aspectFit"></image>
							</view>
							<view class="w100 margin-left">
								<view class="text-black text-lg">银联快付</view>
								<!-- <view class="text-gray text-sm">推荐使用支付宝支付</view> -->
							</view>
							<view class="">
								<radio :class="payment=='kf'?'checked':''" :checked="payment=='kf'?true:false" value="kf"></radio>
							</view>
						</view>
						<!-- <view class="space-between solid-bottom padding-tb-sm align-center" @tap="PaymentBingChange('voucher')" v-if="detail.payment_list.order_voucher_pay == 1">
							<view class="cu-avatar bg-white">
								<image src="https://attract-1251028293.cos.ap-guangzhou.myqcloud.com/images/h5/icon-voucher.png" mode="aspectFit"></image>
							</view>
							<view class="w100 margin-left">
								<view class="text-black text-lg">凭证支付</view>
								<view class="text-gray text-sm">提交资料后需等待后台审核</view>
							</view>
							<view class="">
								<radio :class="payment=='voucher'?'checked':''" :checked="payment=='voucher'?true:false" value="voucher"></radio>
							</view>
						</view> -->
						<view class="space-between  padding-tb-sm align-center" @tap="PaymentBingChange('default')" v-if="detail.payment_list.order_credit_pay == 1">
							<view class="cu-avatar bg-white">
								<image src="https://attract-1251028293.cos.ap-guangzhou.myqcloud.com/icon-menu-2.png" mode="aspectFit"></image>
							</view>
							<view class="w100 margin-left">
								<view class="text-black text-lg">余额支付</view>
								<view class="text-gray text-sm">可用余额 <text v-if="detail.account" class="margin-left-sm text-red">{{detail.account.user_money}}</text></view>
							</view>
							<view class="">
								<radio :class="payment=='default'?'checked':''" :checked="payment=='default'?true:false" value="default"></radio>
							</view>
						</view>
						<view class="space-between  padding-tb-sm align-center" @tap="PaymentBingChange('wallet')" v-if="detail.payment_list.order_wallet_pay == 1">
							<view class="cu-avatar bg-white">
								<image src="https://attract-1251028293.cos.ap-guangzhou.myqcloud.com/icon-menu-2.png" mode="aspectFit"></image>
							</view>
							<view class="w100 margin-left">
								<view class="text-black text-lg">钱包支付</view>
								<view class="text-gray text-sm">钱包余额 <text v-if="detail.account" class="margin-left-sm text-red">{{detail.account.wait_integral}}</text></view>
							</view>
							<view class="">
								<radio :class="payment=='wallet'?'checked':''" :checked="payment=='wallet'?true:false" value="wallet"></radio>
							</view>
						</view>
						<view class="space-between  padding-tb-sm align-center" @tap="PaymentBingChange('integral')" v-if="detail.payment_list.order_integral_pay == 1">
							<view class="cu-avatar bg-white">
								<image src="https://attract-1251028293.cos.ap-guangzhou.myqcloud.com/icon-menu-2.png" mode="aspectFit"></image>
							</view>
							<view class="w100 margin-left">
								<view class="text-black text-lg">积分支付</view>
								<view class="text-gray text-sm">可用积分 <text v-if="detail.account" class="margin-left-sm text-red">{{detail.account.user_integral}}</text></view>
							</view>
							<view class="">
								<radio :class="payment=='integral'?'checked':''" :checked="payment=='integral'?true:false" value="integral"></radio>
							</view>
						</view>
						<!-- <view class="space-between  padding-tb-sm align-center" @tap="PaymentBingChange('frozen')" v-if="detail.payment_list.order_credit_pay == 1">
							<view class="cu-avatar bg-white">
								<image src="https://attract-1251028293.cos.ap-guangzhou.myqcloud.com/icon-menu-2.png" mode="aspectFit"></image>
							</view>
							<view class="w100 margin-left">
								<view class="text-black text-lg">本金余额支付</view>
								<view class="text-gray text-sm">可用本金余额 <text v-if="detail.account" class="margin-left-sm text-red">{{detail.account.frozen_money}}</text></view>
							</view>
							<view class="">
								<radio :class="payment=='frozen'?'checked':''" :checked="payment=='frozen'?true:false" value="frozen"></radio>
							</view>
						</view> -->
						<view class="space-between  padding-tb-sm align-center" @tap="PaymentBingChange('frozen2')" v-if="detail.payment_list.order_frozen_pay == 1">
							<view class="cu-avatar bg-white">
								<image src="https://attract-1251028293.cos.ap-guangzhou.myqcloud.com/icon-menu-2.png" mode="aspectFit"></image>
							</view>
							<view class="w100 margin-left">
								<view class="text-black text-lg">金币</view>
								<view class="text-gray text-sm">可用金币 <text v-if="detail.account" class="margin-left-sm text-red">{{detail.account.frozen_money2}}</text></view>
							</view>
							<view class="">
								<radio :class="payment=='frozen2'?'checked':''" :checked="payment=='frozen2'?true:false" value="frozen2"></radio>
							</view>
						</view>
						<view class="space-between  padding-tb-sm align-center" @tap="PaymentBingChange('wholesale')" v-if="detail.payment_list.order_wholesale_pay == 1">
							<view class="cu-avatar bg-white">
								<image src="https://attract-1251028293.cos.ap-guangzhou.myqcloud.com/icon-menu-2.png" mode="aspectFit"></image>
							</view>
							<view class="w100 margin-left">
								<view class="text-black text-lg">中奖分红奖励</view>
								<view class="text-gray text-sm">可用中奖分红奖励 <text v-if="detail.account" class="margin-left-sm text-red">{{detail.account.wholesale_money}}</text></view>
							</view>
							<view class="">
								<radio :class="payment=='wholesale'?'checked':''" :checked="payment=='wholesale'?true:false" value="wholesale"></radio>
							</view>
						</view>
						<view class="space-between  padding-tb-sm align-center" @tap="PaymentBingChange('pay_zh')" v-if="detail.payment_list.order_zh_pay == 1">
							<view class="cu-avatar bg-white">
								<image src="@/static/coupon-menu-3.png" mode="aspectFit"></image>
							</view>
							<view class="w100 margin-left">
								<view class="text-black text-lg">组合支付</view>
								
							</view>
							<view class="">
								<radio :class="payment=='pay_zh'?'checked':''" :checked="payment=='pay_zh'?true:false" value="pay_zh"></radio>
							</view>
						</view>
					</view>
				</view>

				<view class="margin-top-xl margin-lr-xl padding-top-xl" v-if="detail.is_channel == 1">
					<view class="margin-lr-xl">
						<view class="text-lg text-bold">渠道订单</view>
						<!-- <view class="space-between solid-bottom padding-tb-sm align-center" @tap="PaymentBingChange('wechat')" v-if="detail.payment_list.order_channel_wechat_pay == 1">
							<view class="cu-avatar bg-white">
								<image src="https://attract-1251028293.cos.ap-guangzhou.myqcloud.com/images/h5/icon-wechat.png" mode="aspectFit"></image>
							</view>
							<view class="w100 margin-left">
								<view class="text-black text-lg">微信支付</view>
								<view class="text-gray text-sm">推荐使用微信支付</view>
							</view>
							<view class="">
								<radio :class="payment=='wechat'?'checked':''" :checked="payment=='wechat'?true:false" value="wechat"></radio>
							</view>
						</view> -->
						<!-- <view class="space-between solid-bottom padding-tb-sm align-center" @tap="PaymentBingChange('voucher')" v-if="detail.payment_list.order_channel_voucher_pay == 1">
							<view class="cu-avatar bg-white">
								<image src="https://attract-1251028293.cos.ap-guangzhou.myqcloud.com/images/h5/icon-voucher.png" mode="aspectFit"></image>
							</view>
							<view class="w100 margin-left">
								<view class="text-black text-lg">凭证支付</view>
								<view class="text-gray text-sm">提交资料后需等待后台审核</view>
							</view>
							<view class="">
								<radio :class="payment=='voucher'?'checked':''" :checked="payment=='voucher'?true:false" value="voucher"></radio>
							</view>
						</view> -->
						<view class="space-between  padding-tb-sm align-center" @tap="PaymentBingChange('default')" v-if="detail.payment_list.order_channel_credit_pay == 1">
							<view class="cu-avatar bg-white">
								<image src="https://attract-1251028293.cos.ap-guangzhou.myqcloud.com/icon-menu-2.png" mode="aspectFit"></image>
							</view>
							<view class="w100 margin-left">
								<view class="text-black text-lg">余额支付</view>
								<view class="text-gray text-sm">可用余额 <text v-if="detail.account">{{detail.account.user_money}}</text></view>
							</view>
							<view class="">
								<radio :class="payment=='default'?'checked':''" :checked="payment=='default'?true:false" value="default"></radio>
							</view>
						</view>
					</view>
				</view>

				<view class="margin-top-xl text-center margin-lr">
					<view class="margin-lr margin-top-xl padding-top-xl padding-lr">
						<view class="cu-btn round w100 lg light" :class="['bg-'+theme]" v-if="payLoading">
							<text class="cuIcon-loading2 cuIconfont-spin"></text> 支付中
						</view>
						<view class="cu-btn round w100 lg" :class="['bg-'+theme]" @tap="payOnSubmit" v-else>确定支付</view>
					</view>
				</view>

			</block>
			<view class="margin-lr padding">
				<view class="margin-lr">
					<view class="cu-btn line-black round w100 lg margin-top" @tap="goDetail" v-if="detail && detail.order_status>0 && type == 'order'">订单详情</view>
					<view class="cu-btn line-black round w100 lg margin-top" @tap="gowholesaleDetail" v-if="detail && detail.order_status>0 && type == 'wholesalecash'">拼团详情</view>
				</view>
			</view>
		</view>
		<view class="cu-modal" :class="modalName=='passwordModal'?'show':''">
			<view class="cu-dialog bg-white">
				<view class="cu-bar  justify-end">
					<view class="content">请输入支付密码</view>
					<view class="action" @tap="modalName=''">
						<text class="cuIcon-close text-red"></text>
					</view>
				</view>
				<view class="padding-xl">
					<form>
						<view class="cu-form-group margin-top" style="border: 1px solid #CCCCCC;">
							<view class="title">密码</view>
							<input v-model="password" type="password" placeholder="请输入支付密码" name="input"></input>
						</view>
					</form>
					<view class="cu-btn bg-red round margin-top xl w100" @tap="checkpassword">确定</view>
					<view class="text-blue margin-top" @tap="goPage('/pages/member/password2')">修改支付密码</view>
				</view>
			</view>
		</view>
		<view class="cu-modal" :class="modalName=='zpayModal'?'show':''">
			<view class="cu-dialog bg-white">
				<view class="cu-bar  justify-end">
					<view class="content">组合支付</view>
					<view class="action" @tap="modalName=''">
						<text class="cuIcon-close text-red"></text>
					</view>
				</view>
				<view class="padding-xl">
					<form>
						<view class="cu-form-group margin-top" style="border: 1px solid #CCCCCC;">
							<view class="title">余额</view>
							<input v-model="usemoney" type="number" placeholder="请输入支付的余额" name="input"></input>
						</view>
						<view class="cu-form-group margin-top" style="border: 1px solid #CCCCCC;">
							<view class="title">积分</view>
							<input v-model="unintegral" type="number" placeholder="请输入支付的积分" name="input"></input>
						</view>
						<view class="cu-form-group margin-top" style="border: 1px solid #CCCCCC;">
							<view class="" >
								<view class="margin-lr-xl">
									<!-- #ifdef H5 -->
									<view class="space-between solid-bottom padding-tb-sm align-center" @tap="PaymentOrder('wechat')" v-if="detail && detail.payment_list.order_wechat_pay == 1">
										<view class="cu-avatar bg-white">
											<image src="@/static/cash_wx.png" mode="aspectFit"></image>
										</view>
										<view class="w100 margin-left">
											<view class="text-black text-lg">微信支付</view>
											<view class="text-gray text-sm">推荐使用微信支付</view>
										</view>
										<view class="">
											<radio :class="paymentorder=='wechat'?'checked':''" :checked="paymentorder=='wechat'?true:false" value="wechat"></radio>
										</view>
									</view>
									<!-- #endif -->
									<view class="space-between solid-bottom padding-tb-sm align-center" @tap="PaymentOrder('Alipay')" v-if="detail &&  detail.payment_list.order_ali_pay == 1">
										<view class="cu-avatar bg-white">
											<image src="@/static/cash_ali.png" mode="aspectFit"></image>
										</view>
										<view class="w100 margin-left">
											<view class="text-black text-lg">支付宝支付</view>
											<view class="text-gray text-sm">需要跳转网页支付</view>
										</view>
										<view class="">
											<radio :class="paymentorder=='Alipay'?'checked':''" :checked="paymentorder=='Alipay'?true:false" value="Alipay"></radio>
										</view>
									</view>
								</view>
							</view>
						</view>	
					</form>
					
					<view class="margin-lr margin-top-xl padding-top-xl padding-lr">
						<view class="cu-btn round w100 lg light" :class="['bg-'+theme]" v-if="payLoading">
							<text class="cuIcon-loading2 cuIconfont-spin"></text> 支付中
						</view>
						<view class="cu-btn round w100 lg" :class="['bg-'+theme]" @tap="payzhorder" v-else>确定支付</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: 0,
				detail: null,
				payment: 'default',
				paymentorder:'',
				CLOUDPATH: this.$config.cloudPath,
				theme: this.$config.THEME(),
				payLoading: false,
				joinLog: null,
				config: null,
				member: '',
				modalName: '',
				password: '',
				checkpasswordType: 0,
				checkLoading: false,
				type:'order',
				title:'支付金额',
				wholesale_product_id:0,
				usemoney:'',
				unintegral:'',
				payment_list:'',
			}
		},
		onLoad(options) {
			if (options.type) {
				this.type = options.type;
				if (this.type != 'order') {
					this.title = '代金券支付拼团商品付款邮费'
				}
			}
			if (options.wholesale_product_id) {
				this.wholesale_product_id = options.wholesale_product_id
			}
			if (options.id) {
				this.id = options.id
				this.getOrderView()
			}
			
			this.$common.rmCache('config')
			this.$common.getConfig().then((config) => {
				this.config = config
				this.$nextTick(function() {
					// uni.startPullDownRefresh({})
				})
			})
		},
		onShow() {
			// if (this.$common.getCache('order_change')) {
			// 	this.$common.rmCache('order_change')
			// 	this.getOrderView()
			// }
			this.getOrderView()
			this.$common.getMember().then((member) => {
				this.member = member
				// uni.startPullDownRefresh({})
				//this.getProduct()
			})
			
			
		},
		methods: {
			payzhorder(){
				
				if(this.paymentorder==''){
					if(this.usemoney>0 && this.unintegral>0)
					{
						let pay_tmoney=parseFloat(this.usemoney)+parseFloat(this.unintegral)
						if(pay_tmoney>parseFloat(this.detail.pay_money)){
							this.$common.showError('已超出产品金额')
							return
						}
						if(pay_tmoney<parseFloat(this.detail.pay_money)){
							this.$common.showError('组合金额不足于支付产品金额')
							return
						}
						if (parseFloat(this.detail.account.user_integral) < parseFloat(this.unintegral)) {
							this.$common.showError('积分不足')
							this.joinLoading = false
							return
						}
						if (parseFloat(this.detail.account.user_money) < parseFloat(this.usemoney)) {
							this.$common.showError('余额不足')
							return
						}
						if (this.payLoading ) return
						
						this.$http.post('order_pay_cream', {
								id: this.id,
								zpay_integral: this.unintegral,
								zpay_money: 0,
								is_zpay: 1,
								zpay_type:1,
							})
							.then((response) => {
								uni.hideLoading()
								this.payUserMoney(0, 0, 0)
								this.payLoading = false
							})
							.catch((response) => {
								this.loading = false
								uni.hideLoading()
								this.payLoading = false
							})

					}else{
						this.$common.showError('请选择两种支付方式')
						return
					}
				}else{
					if(this.usemoney>0 || this.unintegral>0)
					{
						if(this.usemoney>0){
							if(parseFloat(this.usemoney)>parseFloat(this.detail.pay_money))
							{
								this.$common.showError('已超出产品金额')
								return
							}
							if (parseFloat(this.detail.account.user_money) < parseFloat(this.usemoney)) {
								this.$common.showError('余额不足')
								return
							}
						}
						if(this.unintegral>0){
							if(parseFloat(this.unintegral)>parseFloat(this.detail.pay_money))
							{
								this.$common.showError('已超出产品金额')
								return
							}
							if (parseFloat(this.member.account.user_integral) < parseFloat(this.unintegral)) {
								this.$common.showError('积分不足')
								this.joinLoading = false
								return
							}
						}
						if(this.usemoney>0 && this.unintegral>0){
							let pay_tmoney=parseFloat(this.usemoney)+parseFloat(this.unintegral)
							if(pay_tmoney>=parseFloat(this.detail.pay_money)){
								this.$common.showError('已超出产品金额')
								return
							}
						}
						if (this.payLoading ) return
						
						this.$http.post('order_pay_cream', {
								id: this.id,
								zpay_integral: this.unintegral,
								zpay_money: this.usemoney,
								is_zpay: 1,
								zpay_type:0,
							})
							.then((response) => {
								if(this.paymentorder=='Alipay'){
									// #ifdef H5
									this.applypay()	//H5支付宝支付
									// #endif
									console.log('app')
									// #ifdef APP-VUE
									this.alipay()
									// #endif
									return
								}else{
									let order_type = this.type
									// #ifdef MP-WEIXIN
									this.mini_pay(this.id)
									// #endif
									
									// #ifdef H5
									
									this.$jwx.payOrder(this.id, order_type).then((response) => {
											this.$common.showSuccess('支付成功', (r) => {
												uni.redirectTo({
													url: "/pages/shop/order/detail?id=" + this.id
												})
											})
										})
										.catch((response) => {
											console.log(response)
											this.loading = false
											this.payLoading = false
									
										})
									return
									// #endif
									
									// #ifdef APP-VUE
									this.$http.post('pay', {
											pay_type: 1,
											trade_type: 'app',
											order_group: order_type,
											data: JSON.stringify({
												"order_id": this.id
											})
										})
										.then((response) => {
											console.log(response)
									
											uni.requestPayment({
												provider: 'wxpay',
												orderInfo: response.data.data.config,
												success: (e) => {
													this.payLoading = false
													this.$common.showSuccess('支付成功', (r) => {
														uni.redirectTo({
															url: "/pages/shop/order/detail?id=" + this.id
														})
													})
												},
												fail: (e) => {
													console.log("fail", e);
													uni.showModal({
														content: "支付失败,原因为: " + e.errMsg,
														showCancel: false
													})
									
													this.payLoading = false
												},
												complete: () => {
													this.payLoading = false
												}
											})
										})
										.catch((response) => {
											console.log((response))
											this.loading = false
											this.payLoading = false
										})
									// #endif
								}
							})
							.catch((response) => {
								this.loading = false
								uni.hideLoading()
								this.payLoading = false
							})
						
					}else{
						this.$common.showError('请选择两种以上支付方式')
						return
					}
				}
			},
			PaymentOrder(e){
				this.paymentorder=e
			},
			PaymentBingChange(e) {
				this.payment = e
			},
			goDetail() {
				uni.navigateTo({
					url: "/pages/shop/order/detail?id=" + this.id
				})
			},
			gowholesaleDetail(){
				uni.navigateTo({
					url: "/pages/shop/marketing/wholesale?id=" + this.wholesale_product_id
				})
			},
			getOrderView() {
				uni.showLoading({
					title: '加载中...'
				})
				this.$http
					.get('order_view', {
						id: this.id,
						simplify: 1,
						type:this.type
					})
					.then((response) => {
						this.detail = response.data.data
						if (this.type == 'wholesalecash') {
							if (this.detail.is_pay == 2) {
								this.detail.order_status = 1;
							}
						}
					})
					.catch((response) => {
						console.log(response)
					})
			},
			payUserMoney(frozen, usewholesale, wholesale_money) {
				this.payLoading = true
				let order_type = this.type
				this.$http.post('pay', {
						pay_type: 5,
						order_group: order_type,
						frozen: frozen,
						usewholesale: usewholesale,
						wholesale_money:wholesale_money,
						data: JSON.stringify({
							"id": this.id
						})
					})
					.then((response) => {
						this.loading = false
						uni.hideLoading()
						console.log(response)
						this.$common.showSuccess('支付成功', (res) => {
							this.$common.rmCache('member')
							if (this.wholesale_product_id > 0) {
								uni.redirectTo({
									url: "/pages/shop/marketing/wholesale?id=" + this.wholesale_product_id
								})
								return
							} else {
								uni.redirectTo({
									url: "/pages/shop/order/detail?id=" + this.id
								})
							}
							
						})
					})
					.catch((response) => {
						this.loading = false
						uni.hideLoading()
						console.log(response)
						this.loading = false
						this.payLoading = false
					})
			},
		
			payOnSubmit() {
				// if(!this.joinLog) this.$common.showError('信息有误')
				if (this.payLoading ) return
				let order_type = this.type
				let _this = this
				
				if (this.payment == 'voucher') {
					this.loading = false
					this.$common.setCache('receivables', this.detail.receivables)
					uni.navigateTo({
						url: "/pages/member/wallet/voucher?id=" + this.id + "&money=" + this.detail.pay_money
					})
				} else if (this.payment == 'frozen2') {
					if (parseFloat(this.detail.account.frozen_money2) < parseFloat(this.detail.pay_money)) {
						this.$common.showError('金币不足')
						return
					}
					this.payLoading = true
					uni.showModal({
						title: '是否确定支付订单，将扣除金币￥' + this.detail.pay_money,
						success(res) {
							if (res.confirm) {
								_this.payUserMoney(0,1,0)
							} else {
								_this.payLoading = false
							}
						},
						fail() {
							_this.payLoading = false
						}
					})
				} else if (this.payment == 'wholesale') {
					if (parseFloat(this.detail.account.wholesale_money) < parseFloat(this.detail.pay_money)) {
						this.$common.showError('中奖分红奖励不足')
						return
					}
					this.payLoading = true
					uni.showModal({
						title: '是否确定支付订单，将扣除中奖分红奖励￥' + this.detail.pay_money,
						success(res) {
							if (res.confirm) {
								_this.payUserMoney(0,0,1)
							} else {
								_this.payLoading = false
							}
						},
						fail() {
							_this.payLoading = false
						}
					})
				} else if (this.payment == 'frozen') {
					if (parseFloat(this.detail.account.frozen_money) < parseFloat(this.detail.pay_money)) {
						this.$common.showError('余额不足')
						return
					}
					this.payLoading = true
					uni.showModal({
						title: '是否确定支付订单，将扣除本金余额￥' + this.detail.pay_money,
						success(res) {
							if (res.confirm) {
								// _this.payUserMoney(1,0,0)
								_this.checkpasswordType = 2
								_this.modalName = 'passwordModal'
							} else {
								_this.payLoading = false
							}
						},
						fail() {
							_this.payLoading = false
						}
					})
				} else if (this.payment == 'wallet') {
					if (parseFloat(this.detail.account.wait_integral) < parseFloat(this.detail.pay_money)) {
						this.$common.showError('钱包余额不足')
						return
					}
					this.payLoading = true
					uni.showModal({
						title: '是否确定支付订单，将扣除余额￥' + this.detail.pay_money,
						success(res) {
							if (res.confirm) {
								_this.payUserMoney(3,0,0)
							} else {
								_this.payLoading = false
							}
						},
						fail() {
							_this.payLoading = false
						}
					})
				} else if (this.payment == 'default') {
					if (parseFloat(this.detail.account.user_money) < parseFloat(this.detail.pay_money)) {
						this.$common.showError('余额不足')
						return
					}
					this.payLoading = true
					uni.showModal({
						title: '是否确定支付订单，将扣除余额￥' + this.detail.pay_money,
						success(res) {
							if (res.confirm) {
								// _this.payUserMoney(0,0,0)
								_this.checkpasswordType = 1
								_this.modalName = 'passwordModal'
							} else {
								_this.payLoading = false
							}
						},
						fail() {
							_this.payLoading = false
						}
					})
				} else if (this.payment == 'pay_zh') {
					
					this.modalName = 'zpayModal'
				}else if (this.payment == 'integral') {
				
					// var paym = this.detail.pay_money * this.config.integral_withdraw
					var paym = this.detail.pay_money 
					console.log(paym)
					if (parseFloat(this.member.account.user_integral) < paym) {
						this.$common.showError('积分不足')
						this.joinLoading = false
						return
					}
					
					uni.showModal({
						title: '是否确定支付订单，将扣除积分￥' + paym,
						success(res) {
							if (res.confirm) {
								
								_this.$http.post('pay', {
										pay_type: 7,
										order_group: "order",
										frozen: 1,
										data: JSON.stringify({
											"order_id": _this.detail.product[0]['order_id']
										})
									})
									.then((response) => {
										_this.loading = false
										uni.hideLoading()
										console.log(response)
										_this.$common.showSuccess('支付成功', (res) => {
											_this.$common.rmCache('member')
											uni.redirectTo({
												url: "/pages/shop/order/detail?id=" + _this.id
											})
										})
									})
									.catch((response) => {
										_this.loading = false
										uni.hideLoading()
										console.log(response)
										_this.loading = false
										_this.payLoading = false
									})
								
								
							} else {
								_this.payLoading = false
								_this.joinLoading = false
							}
						},
						fail() {
							_this.payLoading = false
							_this.joinLoading = false
						}
					})
				} else if (this.payment == 'wechat') {
					this.payLoading = true
					// #ifdef MP-WEIXIN
					this.mini_pay(this.id)
					// #endif

					// #ifdef H5
					
					this.$jwx.payOrder(this.id, order_type).then((response) => {
							this.$common.showSuccess('支付成功', (r) => {
								uni.redirectTo({
									url: "/pages/shop/order/detail?id=" + this.id
								})
							})
						})
						.catch((response) => {
							console.log(response)
							this.loading = false
							this.payLoading = false

						})
					return
					// #endif

					// #ifdef APP-VUE
					this.$http.post('pay', {
							pay_type: 1,
							trade_type: 'app',
							order_group: order_type,
							data: JSON.stringify({
								"order_id": this.id
							})
						})
						.then((response) => {
							console.log(response)

							uni.requestPayment({
								provider: 'wxpay',
								orderInfo: response.data.data.config,
								success: (e) => {
									this.payLoading = false
									this.$common.showSuccess('支付成功', (r) => {
										uni.redirectTo({
											url: "/pages/shop/order/detail?id=" + this.id
										})
									})
								},
								fail: (e) => {
									console.log("fail", e);
									uni.showModal({
										content: "支付失败,原因为: " + e.errMsg,
										showCancel: false
									})

									this.payLoading = false
								},
								complete: () => {
									this.payLoading = false
								}
							})
						})
						.catch((response) => {
							console.log((response))
							this.loading = false
							this.payLoading = false
						})
					// #endif

				} else if (this.payment == 'gd') {
					
					// #ifdef H5
					this.gdpay()	//广东快付微信H5支付
					return
					// #endif
					
					// #ifdef APP-VUE
					// this.gdwxapp()	//广东快付微信APP支付
					// #endif
					return 

				} else if (this.payment == 'Alipay') {
					
					// #ifdef H5
					this.applypay()	//H5支付宝支付
					// #endif
					console.log('app')
					// #ifdef APP-VUE
					this.alipay()
					// #endif
					return

				} else if (this.payment == 'gd1') {
					
					// #ifdef H5
					this.applykf()	//广东支付支支付
					// #endif
					// #ifdef APP-VUE
					this.gdpay1()	//广东支付支付宝
					// #endif
					return 

				} else if (this.payment == 'hj1') {
					
					
					this.applyhj()	//广东支付支支付
					
					// #ifdef APP-VUE
					// #endif
					return 

				} else if (this.payment == 'hj') {
					
					// #ifdef H5
					this.hjpay()	//汇聚微信
					// #endif
					// #ifdef APP-VUE
					
					// #endif
					return 

				}  if (this.payment == 'hjapp') {
					
					// #ifdef APP-VUE
					this.hjapppay()
					
					// #endif
					return 

				}else if (this.payment == 'kf') {
					this.checkpasswordType = 3
					this.modalName = 'passwordModal'
					return 
				} 
				// else {
				// 	this.$common.showError('请选择正确的支付方式')
				// }
			},
			hjapppay(){
				 let id = this.id
			
				uni.showLoading({
					'title' : '加载中...'
				})
				let order_type = this.type
				this.$http.post('pay', {
						pay_type: 1,
						trade_type: 'hjapp',
						order_group: order_type,
						data: JSON.stringify({
							 "order_id": id
						})
					})
					.then((response) => {
						console.log(response.data.data.config);
						
						if (response.data.data.config) {
							// this.goMiniProgram(response.data.data.config.data)
							// console.log(response.data.data.config.qrData)
							// JSON.parse(response.data.data.config.qrData)
							if (response.data.data.config.status == 200) {
								this.goMiniProgram(response.data.data.config.data)
							} else {
								this.$common.showError('配置有误1')
							}
							
							uni.hideLoading()
							return false;
							// window.location.href = decodeURIComponent(response.data.data.config.qrData)
						} else {
							uni.hideLoading()
							this.$common.showError('配置有误1')
						}
					})
					.catch((response) => {
						this.$common.showError('配置有误2')
					})
			},
			goMiniProgram(data) {
				console.log('开启调起小程序支付')
				
				 data = JSON.stringify(data)
				// console.log('pages/payIndex/payIndex?rc_result='+data)
				plus.share.getServices(res => {
					this.sweixin = res.find(i => i.id === 'weixin')
					if (this.sweixin) {
						this.sweixin.launchMiniProgram({
							id: 'gh_3d8e42910df0',
							path: 'pages/payIndex/payIndex?rc_result='+data,
							type:0
						}, res => {
							console.log('res', JSON.stringify(res))
						}, err => {
							console.log('err', JSON.stringify(err))
						})
					} else {
						// 没有获取到微信分享服务
						console.log('没有获取到微信分享服务')
					}
				}, err => {
					// 获取分享服务列表失败
					console.log('获取分享服务列表失败')
				});
				// #ifdef APP-PLUS
				// #endif
			},
			cardKf(){
			    uni.showLoading({
			     'title' : '加载中...'
			    })
			   let id = this.id
			   let order_type = this.type
			    this.$http.post('pay', {
			      pay_type: 99,
			      trade_type: 'kf',
			      order_group: order_type,
			      data: JSON.stringify({
			      "order_id": id
			      })
			     })
			     .then((response) => {
			      if (response.data.data.config != '' && response.data.data.config != null) {
			       this.adddata1 = response.data.data.config
				   if (response.data.data.config.status == 200) {
					  this.loading = false
					  this.payLoading = false
					  this.$common.showSuccess('支付成功', (r) => {
					  	uni.redirectTo({
					  		url: "/pages/shop/order/detail?id=" + this.id
					  	})
					  })
				   } else {
					   this.$common.showError('支付失败')
						 this.loading = false
						 this.payLoading = false
					   uni.hideLoading()
				   }
			       // this.$common.showSuccess('验证成功', (res) => {
			       //  this.modalName = 'passwordModal'
			       // })
			      }
			      this.loading = false
			      uni.hideLoading()
			      
			     })
			     .catch((response) => {
			      this.loading = false
			      uni.hideLoading()
			      console.log(response)
			      
			     })
			   },
			hjpay(){
				uni.showLoading({
					'title' : '加载中...'
				})
				let id = this.id
				let order_type = this.type
				this.$http.post('pay', {
						pay_type: 1,
						trade_type: 'hj',
						order_group: order_type,
						data: JSON.stringify({
							"order_id": id
						})
					})
					.then((response) => {
						if (response.data.data.config) {
							// console.log(response.data.data.config.qrData)
							// JSON.parse(response.data.data.config.qrData)
							response.data.data.config.qrData = response.data.data.config.data
							response.data.data.config.qrData.timestamp = response.data.data.config.qrData.timeStamp
							console.log(response.data.data.config.qrData)
							uni.hideLoading()
							this.$jwx.readyPay(response.data.data.config.qrData).then((response) => {
								this.loading = false
								this.payLoading = false
								this.$common.showSuccess('支付成功', (r) => {
									uni.redirectTo({
										url: "/pages/shop/order/detail?id=" + this.id
									})
								})
								// this.getTotal()
								uni.hideLoading()
								this.$common.showSuccess('支付成功')
							}, (error) => {
								console.log("fail", error);
								uni.showModal({
									content: "支付失败,原因为: " + error,
									showCancel: false
								})
											
								this.loading = false
							})
							uni.hideLoading()
							return false;
							// window.location.href = decodeURIComponent(response.data.data.config.qrData)
						} else {
							uni.hideLoading()
							this.$common.showError('配置有误1')
						}
					})
					.catch((response) => {
						this.$common.showError('配置有误2')
					})
			},
			//快付微信H5支付
			gdpay(){
				// let money = this.formData.number
				let id = this.id
				let order_type = this.type
				this.$http.post('pay', {
						pay_type: 1,
						trade_type: 'gd',
						order_group: order_type,
						data: JSON.stringify({
							"order_id": id
						})
					})
					.then((response) => {
						if (response.data.data.config) {
							// console.log(response.data.data.config.qrData)
							response.data.data.config.qrData = JSON.parse(response.data.data.config.qrData)
							response.data.data.config.qrData.timestamp = response.data.data.config.qrData.timeStamp
							console.log(response.data.data.config.qrData)
							this.$jwx.readyPay(response.data.data.config.qrData).then((response) => {
								this.loading = false
								this.$common.rmCache('member')
								this.$common.getMember().then((member) => {
									this.member = member
								})
								this.payLoading = false
								this.$common.showSuccess('支付成功', (r) => {
									uni.redirectTo({
										url: "/pages/shop/order/detail?id=" + this.id
									})
								})
								this.$common.showSuccess('支付成功')
							}, (error) => {
								console.log("fail", error);
								uni.showModal({
									content: "支付失败,原因为: " + error,
									showCancel: false
								})
											
								this.loading = false
							})
							return false;
							// window.location.href = decodeURIComponent(response.data.data.config.qrData)
						} else {
							this.$common.showError('配置有误')
						}
					})
					.catch((response) => {
						this.$common.showError('配置有误')
					})
			},
			//原本支付宝H5支付
			applypay(){
				let order_type = this.type
				// #ifdef H5
					let ua = window.navigator.userAgent.toLowerCase()
					//let money = this.formData.number
					let money = this.detail?this.detail.pay_money:0.00
					if (ua.match(/MicroMessenger/i) == 'micromessenger') {
						// this.$common.showError('微信浏览器')
					} else {
						// if ( !this.member.id ) {
						// 	this.$common.showError('用户信息错误')
						// 	this.loading = false
						// 	return 
						// }
						
					}
					var url = this.config.web_url + 'site/whrder?type='+order_type+'&money=' + money +"&member_id="+this.detail.buyer_id+"&id="+this.id
					window.open(url)
				// #endif
			},
			//支付宝快付H5支付
			applykf(){
				let order_type = this.type
				// #ifdef H5
					let ua = window.navigator.userAgent.toLowerCase()
					//let money = this.formData.number
					let money = this.detail?this.detail.pay_money:0.00
					if (ua.match(/MicroMessenger/i) == 'micromessenger') {
						// this.$common.showError('微信浏览器')
					} else {
						// if ( !this.member.id ) {
						// 	this.$common.showError('用户信息错误')
						// 	this.loading = false
						// 	return 
						// }
						
					}
					var url = this.config.web_url + 'site/whrderkf?type='+order_type+'&money=' + money +"&member_id="+this.detail.buyer_id+"&id="+this.id
					window.open(url)
				// #endif
			},
			//支付宝汇聚H5支付
			applyhj(){
				let order_type = this.type
				let money = this.detail?this.detail.pay_money:0.00
				// #ifdef H5
					let ua = window.navigator.userAgent.toLowerCase()
					//let money = this.formData.number
					
					if (ua.match(/MicroMessenger/i) == 'micromessenger') {
						// this.$common.showError('微信浏览器')
					} else {
						// if ( !this.member.id ) {
						// 	this.$common.showError('用户信息错误')
						// 	this.loading = false
						// 	return 
						// }
						
					}
					var url = this.config.web_url + 'site/whrderhj?type='+order_type+'&money=' + money +"&member_id="+this.detail.buyer_id+"&id="+this.id
					window.open(url)
				// #endif
				
				// #ifdef APP-VUE
				var url = this.config.web_url + 'site/whrderhj?type='+order_type+'&money=' + money +"&member_id="+this.detail.buyer_id+"&id="+this.id
				plus.runtime.openURL(url)
				// #endif
			},
			//原本APP支付
			
			alipay(){
				console.log(this.id)
				let order_type = this.type
				let id = this.id
				this.$http.post('pay', {
					pay_type: 2,
					trade_type: 'app',
					order_group: order_type,
					data: JSON.stringify({
						"order_id": id,
						"id": id,
					})
				})
				.then((response) => {
					console.log(response)
					uni.requestPayment({
							provider: 'alipay',
							orderInfo: response.data.data.config.config,
							success: (e) => {
								this.payLoading = false
								this.$common.showSuccess('支付成功', (r) => {
									uni.redirectTo({
										url: "/pages/shop/order/detail?id=" + this.id
									})
								})
							},
							fail: (e) => {
								console.log("fail", e);
								uni.showModal({
									content: "支付失败,原因为: " + e.errMsg,
									showCancel: false
								})
							
								this.payLoading = false
							},
							complete: () => {
								this.payLoading = false
							}
						})
				})
				.catch((response) => {
					reject(response)
				})
			},
			//广东快付支付宝APP支付
			gdpay1(){
				let order_type = this.type
				let id = this.id
				this.$http.post('pay', {
					pay_type: 2,
					trade_type: 'gd',
					order_group: order_type,
					data: JSON.stringify({
						"order_id": id,
						"id": id,
					})
				})
				.then((response) => {
					uni.showLoading({
						'title' : '加载中...'
					})
					console.log(response)
					let url = 'alipayqr://platformapi/startapp?saId=10000007&clientVersion=3.7.0.0718&qrcode=' + response.data.data.config.config.qrData;
				
					 plus.runtime.openURL(url, function (res) {
						uni.hideLoading()
						uni.showToast({
						  icon: "none",
						  title: "请安装支付宝之后再进行支付！",
						});
					  });
					  uni.hideLoading()
					
				})
				.catch((response) => {
					reject(response)
				})
			},
			BackPage(delta) {
				uni.navigateBack({
					delta: delta
				});
			},
			checkpassword() {
				if(this.checkLoading) return
				this.checkLoading = true
				uni.showLoading({
					title: '处理中'
				})
				this.$http.post('check_pay_pw', {
					password: this.password,
				}).then((response) => {
					uni.hideLoading()
					this.$common.showSuccess('验证通过')
					if (this.checkpasswordType == 1) {
						this.payUserMoney(0, 0, 0)
					} else if (this.checkpasswordType == 2) {
						this.payUserMoney(1,0,0)
					} else if (this.checkpasswordType == 3) {
						this.cardKf()
					}
				this.checkLoading = false
				}).catch((response) => {
					uni.hideLoading()
				this.checkLoading = false
				})
			},
		}
	}
</script>

<style>
</style>
